﻿@model ThaireInvestmentWeb.Models.ManageLoanModel
@{
    ViewBag.Title = "ManageLoan";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script>
    $(document).ready(function () {
        $("#ResetBtn").click(function (event) {
            showConfirm(null, ResetBtnAction);
            return false;
        });
        $("#ContractStartDate,#ContractEndDate").datepicker({
            dateFormat: 'dd/mm/yy',
            yearRange: "-30:+40",
            isBuddhist: true,
            showOn: 'button',
            showAnim: 'fadeIn',
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            buttonImage: '@Url.Content("~/Content/images/Calendar.png")'
        });
        $("#LoanBalanceStart").change(FormatNumber2Digits);
        $("#LoanBalanceEnd").change(FormatNumber2Digits);
        //$("#LoanBalanceEnd").change(test);  
    }); 

    //function test() {
    //    alert('mmm');
    //    FormatNumber2Digits($(this));
    //}
    
    function ResetBtnAction(event) {
        window.location.href = 'ManageLoan';
    }  
</script>
<table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%;">
            <div class="navi">
                Instrument Type > Loans
          
            </div>
        </td>
    </tr>
</table>

<table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="38" align="center" style="width: 100%; text-align: center;">Loans</td>
    </tr>
</table>
<table width="951" border="0" align="center">
    <tr>
        <td>
            @using (Html.BeginForm("SearchLoanHeader", "Loan", FormMethod.Post, new { id = "mainForm" }))
            {
                
                 
                <table class="tableform" width="100%" border="5" align="center" cellspacing="2" style="background-color: #E8ECFF;">
                    <tr>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                    <tr>
                        <td width="212">
                            <div align="right">Company<span class="error">*</span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px; text-align: left;">
                            @Html.DropDownListFor(x => x.SelectedCompany, Model.CompanyList)
                            @Html.ValidationMessageFor(model => model.SelectedCompany)
                        </td>
                        <td width="130" align="right"></td>
                        <td>&nbsp;</td>
                        <td width="258"></td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Loan Type : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px; text-align: left;">
                            @Html.DropDownListFor(x => x.SelectedLoanType, Model.LoanTypeList)
                        </td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td style="background-color: #E8ECFF">
                            <div align="right">Contract Number : </div>
                        </td>
                        <td style="background-color: #E8ECFF">&nbsp;</td>
                        <td style="width: 236px; background-color: #E8ECFF; text-align: left;">
                            @Html.TextBoxFor(model => model.ContractNumber)
                            @Html.ValidationMessageFor(model => model.ContractNumber)
                        </td>
                        <td style="background-color: #E8ECFF">&nbsp;</td>
                        <td style="background-color: #E8ECFF">&nbsp;</td>
                        <td style="background-color: #E8ECFF">&nbsp;</td>
                    </tr>
                    <tr>
                        <td style="background-color: #E8ECFF">
                            <div align="right">Borrower Name : </div>
                        </td>
                        <td style="background-color: #E8ECFF">&nbsp;</td>
                        <td style="width: 236px; background-color: #E8ECFF; text-align: left;">
                            @Html.TextBoxFor(model => model.BorrowerName)
                            @Html.ValidationMessageFor(model => model.BorrowerName)
                        </td>
                        <td style="background-color: #E8ECFF">&nbsp;</td>
                        <td style="background-color: #E8ECFF">&nbsp;</td>
                        <td style="background-color: #E8ECFF">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Contract Start Date  : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px; text-align: left;">
                            @Html.TextBoxFor(model => model.ContractStartDate, new { style = "width: 100px;", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.ContractStartDate) })
                            @Html.ValidationMessageFor(model => model.ContractStartDate) (Ex.31/12/2014)</td>
                        <td>
                            <div align="right">Between : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.ContractEndDate, new { style = "width: 100px;", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.ContractEndDate) })
                            @Html.ValidationMessageFor(model => model.ContractEndDate) (Ex.31/12/2014)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Loan Balance  : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px; text-align: left;">
                            @Html.TextBoxFor(model => model.LoanBalanceStart, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.LoanBalanceStart) })
                            @Html.ValidationMessageFor(model => model.LoanBalanceStart)
                            &nbsp; (THB)</td>
                        <td>
                            <div align="right">Between : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.LoanBalanceEnd, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.LoanBalanceEnd) })
                            @Html.ValidationMessageFor(model => model.LoanBalanceEnd)
                            &nbsp; (THB)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Status   : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px; text-align: left;">
                            @Html.DropDownListFor(x => x.SelectedStatus, Model.StatusList)
                            &nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="6" style="text-align: center">
                            <input type="submit" name="SearchBtn" value=" Search " class="button">&nbsp;&nbsp;&nbsp;
                            <input type="button" id="ResetBtn" name="ResetBtn" value=" Reset " class="button" />

                        </td>
                    </tr>
                    <tr>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                </table>
               
             
            }
            <table width="95%" border="0" align="center">
                <tr>
                    <td>
                        <div align="left">
                            <input type="button" name="Submit22" value=" New " class="button" onclick="self.location.href = 'EditLoanHeader';">
                            &nbsp;&nbsp;&nbsp;
                        </div>
                    </td>
                    <td>
                        <div align="right">
                            &nbsp;
                        </div>
                    </td>
                </tr>
            </table>
            @{
 
                if (Model.Result != null)
                {
                    var grid = new WebGrid(source: Model.Result, ajaxUpdateContainerId: "grid", rowsPerPage: 25, canPage: true);
                @grid.GetHtml(htmlAttributes: new { id = "grid" }, tableStyle: "tablelist", headerStyle: "headertable", displayHeader: @Model.Result.Count > 0,
                      columns: grid.Columns(
                                grid.Column(header: "NO.", format: item => (item.WebGrid.Rows.IndexOf(item) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),

                                grid.Column(columnName: "CompanyName", header: "Company", canSort: false),
                                grid.Column(columnName: "LoanTypeName", header: "Loan Type", canSort: false),
                                grid.Column(columnName: "ContractNumber", header: "Contract Number", canSort: false),
                                grid.Column(columnName: "BorrowerName", header: "Borrower Name", canSort: false),
                                grid.Column(columnName: "ContractStartDate", header: "Start Date", canSort: false, format: (item) => item.ContractStartDate != null ? item.ContractStartDate.ToString("dd/MM/yyyy") : ""),
                                grid.Column(columnName: "ContractAmount", header: "Loan Balance", canSort: false, style: "currencyAlignment", format: @<text>@String.Format("{0,10:0.00}", (decimal)(100/3)) </text>),
                                grid.Column(columnName: "Status", header: "Status", canSort: false),

                                grid.Column(header: "Detail", style: "table_col15", format:
                                    @<text>
                <input type="image" onClick="go('@Url.Action("EditLoanHeader", "Loan", new { headerId = item.LoansHeaderID })    ');"  src="@Url.Content("~/Content/images/b_edit.gif")"  title="แก้ไข">
                </text>)
                        ));
                }
            }

        </td>
    </tr>
</table>
